<template>
	<view class="">
		<view class="wrap">
			<view class="detail-top">
				<image class="" :src="$IMG_URL+detailInfo.image" mode=""></image>
			</view>
			<image class="detail-top-img" src="/static/index/detail-bg.png" mode=""></image>
			<view class="detail-top-price">
				{{isJifen == 1 ? '￥':'积分:'}}<text>{{detailInfo.price}}</text>
			</view>
			<view class="detail-top-title">
				{{detailInfo.name}}
			</view>
			<view class="detail-top-name" v-show="detailType == 1 && detailInfo.bt == 1">
				补贴金额:<text>{{detailInfo.subsidy}}</text>
			</view>
			<view class="detail-top-name" v-show="detailType == 1">
				所属人:<text>{{detailInfo.nickname}}</text>
			</view>
		</view>
		<view class="wrap-centent">
			<view class="wrap-centent-title">
				<view class="wrap-centent-border"></view>
				<view class="wrap-centent-name">商品详情</view>
			</view>
			<view class="wrap-centent-moral">
				<u-parse :content="detailInfo.content"></u-parse>
			</view>
		</view>
		<view class="detail-bottom" v-show="detailType == 1">
			<view class="detail-bottom-left">
				￥<text>{{detailInfo.price}}</text>
			</view>
			<view class="detail-bottom-right" @click="orderBySnapped">
				立即抢购
			</view>
		</view>
		<view v-show="detailType == 2" class="detail-bottom-btn" @click="exchangeBtn">
			兑换
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detailType: 1, //1普通商品详情 2 积分详情
				detailInfo: {},
				id:'',
				activityId:'',
				isJifen:1//true积分  false 其他商品
			}
		},
		onLoad(options) {
			this.activityId = options.activityId
			this.detailType = options.detailType
			this.isJifen = options.isJifen
			this.id =options.id 
			this.init(options.id);
		},
		methods: {
			// 跳转
			navigator(url) {
				uni.navigateTo({
					url: url
				})
			},
			// 获取商品详情
			init(id) {
				this.$http('index.getGoodsDetails', {
					goods_id: id
				}, '获取中...').then(res => {
					if (res.code == 1) {
						this.detailInfo = res.data
					}
				})
			},
			orderBySnapped() {
				let that = this;
				uni.showLoading({
					title: '抢购中'
				});
				uni.showModal({
					title: '提示',
					content: '商品所属人:'+that.detailInfo.nickname+'\r\n商品金额:'+that.detailInfo.price,
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认抢购", // 确认按钮的文字  
					showCancel: true, // 是否显示取消按钮，默认为 true
					confirmColor: '#f55850',
					cancelColor: '#39B54A',
					success: (res) => {
					if(res.confirm) {  
						that.$http('index.createOrderBySnapped', {
							goods_id: that.id,
							activity_id:that.activityId
						}, '抢购中...').then(res => {
							if (res.code == 1) {
								uni.hideLoading();
								that.navigator('/pages/index/purchaseSuccess/purchaseSuccess?typeImg='+1+'&title='+'抢购成功'+'&typeBtn='+2)
							}else{
								uni.hideLoading();
								uni.showToast({
									icon:'none',
									title:res.msg
								})
								// this.navigator('/pages/index/purchaseSuccess/purchaseSuccess?typeImg='+2+'&title='+'抢购失败'+'&typeBtn='+1)
							}
						})
					} else {  
						console.log('cancel') //点击取消之后执行的代码
						}  
					} 
				})
			},
			// 兑换
			exchangeBtn(){
				this.$http('integral.buyNowConfirmOrder', {
					goods_id: this.id,
				}, '兑换中...').then(res => {
					if (res.code == 1) {
						uni.setStorageSync('conmeAddressTitle','')
						uni.setStorageSync('goodsInfo',res.data.goods)
						// console.log(uni.getStorageSync('goodsInfo'),333)
						this.navigator('/pages/message/confirmOrder/confirmOrder?confirmType='+1+'&goods_id='+this.id+'&confirmTitle='+'确认订单')
					}else{
						uni.showToast({
							icon:'none',
							title:res.msg
						})
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F7F9;
	}

	.wrap {
		background-color: #fff;
		padding-bottom: 30rpx;
	}

	.detail-top {
		width: 100%;
		height: 660rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.detail-top-img {
		position: absolute;
		width: 100%;
		height: 80rpx;
		z-index: 99;
		top: 580rpx;
	}

	.detail-top-price {
		position: absolute;
		width: 100%;
		z-index: 99;
		top: 600rpx;
		font-weight: bold;
		font-size: 26rpx;
		color: #FFFFFF;
		left: 32rpx;

		text {
			font-size: 36rpx;
		}
	}

	.detail-top-title {
		font-weight: bold;
		font-size: 32rpx;
		color: #333333;
		margin: 20rpx;
	}

	.detail-top-name {
		font-weight: 500;
		font-size: 24rpx;
		color: #999999;
		margin-left: 27rpx;

		text {
			color: #333333;
			margin-left: 20rpx;
		}
	}

	.wrap-centent {
		margin-top: 20rpx;
		background-color: #fff;
		padding: 20rpx;
		padding-bottom: 150rpx;
	}

	.wrap-centent-title {
		display: flex;
		margin-bottom: 12rpx;

		.wrap-centent-border {
			width: 8rpx;
			height: 28rpx;
			background: #287E34;
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			margin-top: 10rpx;
		}

		.wrap-centent-name {
			font-weight: bold;
			font-size: 32rpx;
			color: #333333;
			margin-left: 27rpx;
		}

	}

	// .wrap-centent-img {
	// 	width: 100%;
	// 	height: 340rpx;
	// 	margin: 20rpx auto;
	// 	border-radius: 20rpx;
	// }

	.wrap-centent-moral {
		font-weight: 500;
		font-size: 28rpx;
		color: #666666;
		line-height: 46rpx;
	}

	.detail-bottom {
		width: 100%;
		height: 90rpx;
		background: #FFFFFF;
		position: fixed;
		z-index: 200;
		bottom: 0;
		display: flex;
		justify-content: space-between;

		.detail-bottom-left {
			font-weight: bold;
			font-size: 24rpx;
			color: #DD0403;
			margin: 30rpx 0 0 50rpx;

			text {
				font-size: 32rpx;
			}
		}

		.detail-bottom-right {
			width: 230rpx;
			height: 90rpx;
			background: #287E34;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 90rpx;
			text-align: center;
		}

	}

	.detail-bottom-btn {
		position: fixed;
		z-index: 200;
		bottom: 30rpx;
		width: 686rpx;
		height: 88rpx;
		background: linear-gradient(90deg, #6AAE2B 0%, #1B7E38 100%);
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		left: 50%;
		transform: translate(-50%);
		border-radius: 50rpx;
	}
</style>